﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YArchitech.Revit;
using YJKExcelFormTool.Utilities;

namespace YJKExcelFormTool.Analyser
{
	public class ParallelLinesComparer : IComparer<Line>
	{
		public ParallelLinesComparer(XYZ direction)
		{
			this.m_Direction = direction;
		}

		public int Compare(Line line1, Line line2)
		{
			XYZ hyendPoint = line1.GetEndPoint(0);
			XYZ xyz = (Geometry.CalculateFootPoint(line2, hyendPoint) - hyendPoint).Normalize();
			if (Geometry.IsEqual(xyz.GetLength(), 0.0))
			{
				return 0;
			}
			if (xyz.IsAlmostEqualTo(this.m_Direction))
			{
				return -1;
			}
			if (xyz.IsAlmostEqualTo(-this.m_Direction))
			{
				return 1;
			}
			throw new Exception("errored direction");
		}

		private XYZ m_Direction;
	}
}
